package com.mooue.controller;

import com.fresh.common.ResponseResult;
import com.mooue.entity.Store;
import com.mooue.service.StoreService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 仓库表(Store)表控制层
 *
 * @author bsciology
 * @since 2023-08-11 15:00:23
 */
@RestController
@RequestMapping("store")
public class StoreController {
    /**
     * 服务对象
     */
    @Resource
    private StoreService storeService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseResult<Store> queryById(@PathVariable("id") Integer id) {
        return new ResponseResult<>(200,"ok",this.storeService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param store 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseResult<Store> add(Store store) {
        return new ResponseResult<>(200,"ok",this.storeService.insert(store));
    }

    /**
     * 编辑数据
     *
     * @param store 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseResult<Store> edit(Store store) {
        return new ResponseResult<>(200,"ok",this.storeService.update(store));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseResult<Boolean> deleteById(Integer id) {
        return new ResponseResult<>(200,"ok",this.storeService.deleteById(id));
    }

}

